Add ESC to abort image pull with fall-back to local#341
Draft
gtsiolis wants to merge 2 commits into
Draft
Conversation
During a floating-tag pull, if a local copy of the image is already present and we're interactive, show "press esc to keep current version" once real layer download begins. Pressing ESC cancels only the in-flight pull (Ctrl+C still quits) and starts the emulator with the existing local image. A failed pull (e.g. offline) with a local copy present now falls back automatically instead of aborting the start. The domain stays UI-free: pullImage runs the pull under a per-pull cancel context and selects on a skip channel the TUI signals via the new PullSkippableEvent. Generated with [Linear](https://linear.app/localstack/issue/PRO-324/esc-to-abort-image-pull-with-fall-back-to-local#agent-session-ee6a32f4) Co-authored-by: linear-code[bot] <222613912+linear-code[bot]@users.noreply.github.com>
Two correctness fixes in the ESC-to-abort-pull flow (PRO-324): 1. Deadlock on an immediate pull error. DockerRuntime.PullImage returned the error from client.ImagePull before registering `defer close(progress)`, so the progress channel was never closed on that path. pullImage now waits on the progress goroutine to drain (`<-progressDone`), turning that prior goroutine leak into a hang of the whole start flow — exactly in the offline/unreachable-registry scenario this feature targets. Close progress unconditionally so callers can never hang. Regression test points a DockerRuntime at an unreachable socket and asserts progress is closed. 2. Ctrl+C during a pull was conflated with a pull failure. A cancelled parent context surfaced as a pull error and, when a local image existed, was swallowed by the local-image fall-back (returning success), so the start continued on an already-cancelled context instead of aborting. Propagate context.Canceled before the fall-back. Regression test cancels the parent context mid-pull and asserts the cancellation propagates. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
c96a6a7 to
970b218
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pulling a floating-tag emulator image (
latest/empty) used to block the entire start with no way out — the "20-minute wait at a booth with no abort" complaint. This makes the pull interruptible and resilient, without a pre-pull prompt or a registry digest probe.Implements PRO-324. Builds on PRO-323 (
ImageExists). Idea credit: Carole.Behavior
q) still quits the whole program.ErrorEvent+ silent error + telemetry), exactly as before.The hint appears only once Docker reports actual layer download, so it never flashes on an "up to date" / cache hit.
How it works
pullImageschecksImageExistsfor every image and delegates each pull to a newpullImagehelper.pullImageruns the pull under a per-pull cancel context andselects on either the pull result or a buffered skip channel.output.PullSkippableEventcarrying a cancel channel it owns (mirroring the existingUserInputRequestEvent/ResponseChshape). The TUI binds ESC during the pulling phase to signal that channel; ESC is inert otherwise. Non-interactive mode never emits the event, andPlainSinkhas no rendering for it.localExists && interactiveand only armed after aDownloadingprogress status arrives, so the domain never blocks where a prompt couldn't be answered.Robustness fixes (second commit)
Wiring the new
select+ progress-drain surfaced two latent issues, fixed here:DockerRuntime.PullImagereturned an immediateImagePullerror before registeringdefer close(progress), leaving the progress channel open on that path.pullImagenow waits for the progress goroutine to drain, which turned the old benign goroutine leak into a hang of the whole start flow — squarely in the offline scenario this feature targets.PullImagenow closesprogressunconditionally.pullImagenow propagatescontext.Canceledbefore the fall-back.Decisions
Tests
internal/container/start_test.go— ESC → skip + use local; pull error + local → auto fall-back; pull error + no local → fatal; non-interactive → never skippable; parent-context cancel → propagates (not swallowed).internal/runtime/docker_test.go—PullImageclosesprogresseven whenImagePullfails immediately (timeout-guarded deadlock regression).internal/ui/app_test.go— ESC signals the skip channel and shows the hint without quitting; ESC is inert with no pull in flight.internal/output/plain_sink_test.go—PlainSinksuppressesPullSkippableEvent.The issue called for PTY integration coverage, but the two real-world triggers are non-deterministic to stage — forcing an offline pull error means intercepting the hardcoded registry, and an ESC-during-pull PTY test depends on pull timing. The behavior is instead covered by the deterministic unit/UI tests above.